//
//  MenuItemCell.m
//  MoneyIndividual
//
//  Created by Le Anh Tai on 12/28/13.
//  Copyright (c) 2013 Le Anh Tai. All rights reserved.
//

#import "MenuItemCell.h"

@implementation MenuItemCell

- (id)initWithNormalImage:(UIImage*)normalImage selectedImage:(UIImage*)selectedImage reuseIdentifier:(NSString*)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        
        _titleLabel = [UILabel newTitleLabel];
        [_subView addSubview:_titleLabel];
        
        _descriptionLabel = [UILabel newDescriptionLabel];
        [_subView addSubview:_descriptionLabel];

        _normalImage = normalImage;
        _highlightedImage = selectedImage;
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    int fontHei;
    
    _titleLabel.frame = RECT(self.imageView.right + PADDING, PADDING, _subView.width - PADDING*2 - self.imageView.right, [_titleLabel fontHeight]);
    
    fontHei = _descriptionLabel.fontHeight;
    _descriptionLabel.frame = RECT(_titleLabel.left, _subView.height - PADDING - fontHei, _titleLabel.width, fontHei);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    if (selected)
    {
        if (_highlightedImage)
        {
            [self.imageView setImage:_highlightedImage];
        }
        
        _subView.backgroundColor = COLOR_GRAY;
        [_titleLabel setTextColor:COLOR_WHITE_PURE];
        [_descriptionLabel setTextColor:COLOR_GRAY_LIGHT];
    }
    else
    {
        if (_normalImage)
        {
            [self.imageView setImage:_normalImage];
        }
        
        _subView.backgroundColor = COLOR_WHITE_PURE;
        [_titleLabel setTextColor:COLOR_BLACK_PURE];
        [_descriptionLabel setTextColor:COLOR_GRAY_DARK];
    }
}

@end
